home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / romize.zip / TC_UTIL.ZIP / EXMPL.C next >
Text File  |  1989-09-15  |  1KB  |  56 lines

  1. /* ROMEXMPL.C   - Example ROMable Turbo C program */
  2.  
  3. #include <dos.h>
  4.  
  5.  
  6. #define  portin         0x300
  7. #define  portout        0x301
  8.  
  9. /* Here are examples of how to re-create some of
  10.     the library string functions */
  11.  
  12. int glob_var;
  13.  
  14. void strmv(char *dest, char *source) { /* like copy, but does not move
  15.                                          terminating null */
  16.   while (*source) *dest++ = *source++;
  17. }
  18.  
  19. int strlen(char *source) {
  20.   int i;
  21.   i = 0;
  22.   while (*source++) i++;
  23.   return (i);
  24. }
  25.  
  26. void strcpy(char *dest, char *source) {
  27.   while (*source) *dest++ = *source++;
  28.   *dest = *source;  /* move terminator */
  29. }
  30.  
  31. void send_mess(char *p) {
  32.  
  33.   while (*p) outportb(portout,*p++);
  34. }
  35.  
  36. void do_stuff() {
  37.  
  38.   static char *menu[] = { "Choice A", "Choice B", "Choice C"};
  39.   int i;
  40.  
  41.   i = inportb(portin);
  42.   send_mess(menu[i]);
  43. }
  44.  
  45. void main(void) {
  46. int main_var;
  47.     do {
  48.         glob_var=1;
  49.         do_stuff();
  50.         main_var=2;
  51.   } while (1);
  52.  
  53.   /* don't return from main, there ain't no place to go */
  54.  
  55. }
  56.